/*
 * @Descripttion: 
 * @Author: cuidm
 * @Date: 2022-05-25 14:22:18
 * @LastEditors: cuidm
 * @LastEditTime: 2022-05-25 15:23:49
 */
import React, { useState, useEffect, Fragment } from "react";
import { message } from "antd";;
import { HcpTipModal } from "@/components";
import cmdbres from "@/data/cmdbres";
import request from "@/utils/request";
import hcpUtils from "@/utils/hcpUtils";
const user = hcpUtils.getUser();

const ExecuteRule = ({ info, visible, setVisible, onDeleteFinish }) => {
    const [loading, setLoading] = useState(false);

    const onFinish = async () => {
        setLoading(true);
        let res = await request({
            ...cmdbres.executeModuleAssociateRule(),
            data: {
                ruleId: info.ruleId
            }
        });
        setLoading(false);
        setVisible(false);
        if (res && (res.code == 200)) {
            message.success("执行规则指令下发成功！");
            if (typeof onDeleteFinish == "function") onDeleteFinish(res);
        } else {
            if(res) message.error(res.msg);
        }
    };

    return (
        <HcpTipModal
            title="执行关联规则"
            visible={visible}
            loading={loading}
            onFinish={onFinish}
            onCancel={() => { setVisible(false) }}
            content={
                <>
                    <div className="main-content">
                        <span className="main-content-info">确定要立即执行关联规则吗？</span>
                    </div>
                </>
            }
        />
    );
};

export default ExecuteRule;
